#include "CppUnitTest.h"
#include "GetFileInfoTools.h"
#include <iostream>

using namespace std;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace GetFileInfoDllTest
{
	TEST_CLASS(GetFileInfoDllTest)
	{
	public:
		
		TEST_METHOD(Test_GetFileInfo)
		{
			string enumText[33];
			//Invalid = 0, None = 1, JUNCTION = 2, SYMLINK = 4, SYMLINKD = 8, HardLink = 16, SingleFile = 32, NotSupport = None | SingleFile
			enumText[1] = "None";
			enumText[2] = "JUNCTION";
			enumText[4] = "SYMLINK";
			enumText[8] = "SYMLINKD";
			enumText[16] = "HardLink";
			enumText[32] = "SingleFile";
			const char* rl = "\r\n";
			int error;
			LinkType lt = GetFileLinkType(L"D:\\Program\\media Program\\Foobar2000\\x64\\cache\\", false, &error);
			Logger::WriteMessage(enumText[lt].c_str());
			Logger::WriteMessage(rl);

			lt = GetFileLinkType(L"C:\\Program Files\\Common Files\\ChaosGroup\\logs\\user.log", false, &error);
			Logger::WriteMessage(enumText[lt].c_str());
			Logger::WriteMessage(rl);

			lt = GetFileLinkType(L"I:\\Temp\\WorkTemp\\MusicLyricsManagement\\MusicLyricsManagement\\FFmpegLib\\avutil-58.dll", false, &error);
			Logger::WriteMessage(enumText[lt].c_str());
			Logger::WriteMessage(rl);

			/*lt = GetFileLinkType(L"I:\\Temp\\WorkTemp\\SymbolicLinkManage\\MSTestProject\\test.txt", false, &error);
			Logger::WriteMessage(enumText[lt].c_str());*/
		}

		TEST_METHOD(Test_GetFilelingHardLinks)
		{
			wchar_t* result = (wchar_t*)GetFilelingHardLinks(L"I:\\Temp\\WorkTemp\\MusicLyricsManagement\\MusicLyricsManagement\\FFmpegLib\\avutil-58.dll",true);
			int32_t len = 0;
			const int32_t UintSize = sizeof(uint32_t);
			byte* current = (byte*)result;
			len = *((int32_t*)current) - UintSize;
			current += UintSize;

			while (true)
			{
				wchar_t* curr = (wchar_t*)LocalAlloc(LPTR, len);
				memcpy(curr, current, len);
				Logger::WriteMessage(curr);
				Logger::WriteMessage(L"\r\n");
				LocalFree(curr);

				current += len;
				len = *((int32_t*)current) - UintSize;
				if (len < 1)
					break;
				current += UintSize;
			}

						
			LocalFree(result);
		}

		TEST_METHOD(Test_GetFilelingHardLinksAsterisk)
		{
			wchar_t* result = (wchar_t*)GetFilelingHardLinks(L"I:\\Temp\\WorkTemp\\MusicLyricsManagement\\MusicLyricsManagement\\FFmpegLib\\avutil-58.dll", false);

			Logger::WriteMessage(result);
			LocalFree(result);
		}

		TEST_METHOD(Test_GetFileLinkCount)
		{
			int error;
			int32_t result = GetFileLinkCount(L"I:\\Temp\\WorkTemp\\MusicLyricsManagement\\MusicLyricsManagement\\FFmpegLib\\avutil-58.dll", true, &error);
			Logger::WriteMessage(std::to_string(result).c_str());
		}
	};
}
